﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Management;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VideoClassLibrary.CacheManager;
using VideoClassLibrary.Extension;
using VideoClassLibrary.Model;
using VideoClassLibrary.BusinessLogicLayer;

public partial class SchoolLogin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        
    }
    protected void alert(string key, string msg)
    {
        if (!Page.ClientScript.IsClientScriptBlockRegistered(key))
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), key, "javascript:alert('" + msg + "');", true);
        }

    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        try
        {
            UserModule userHelper = new UserModule();
            V_adminUser currentAdminUser = userHelper.AdminUserLogin(txtName.Text.Trim(), txtPwd.Text.Trim());
            if (currentAdminUser != null)
            {
                
                
                if (currentAdminUser.VA_type == 0 || currentAdminUser.Va_IsEnable == 0)
                {
                    PageHelper.AlterMsgAndRedirect("没有权限", "SchoolLogin.aspx?exit=exit&T=U");
                }
                else
                {
                    Session["currentAdminUser"] = currentAdminUser;
                    CommonCacheManager.AddCacheData<V_adminUser>("AdminUser", currentAdminUser, 60);
                    if (!String.IsNullOrEmpty(Request["returnUrl"]))
                    {
                        Response.Redirect(Request["returnUrl"]);
                    }
                    else
                    {
                        Response.Redirect("AdminIndex.aspx");
                    }
                }

            }
            else
            {
                alert("error", "用户不存在或者用户名、密码不正确！");
            }
        }
        catch (Exception ex)
        {
            alert("error", "登录失败:" + ex.Message);
        }
    }

  

}
